package com.three.service.impl;

import com.baor.baseUtil.R;
import com.three.dao.LeavesDao;
import com.three.domain.Leaves;
import com.three.service.LeavesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Transactional(rollbackFor = Exception.class)
public class LeavesServiecImpl implements LeavesService {
    @Autowired
    private LeavesDao leavesDao;

    @Override
    public R leavesList(Integer id, Integer pageIndex, Integer pageSize,String date) {
        pageIndex = (pageIndex - 1) * pageSize;
        double pageCount = leavesDao.PageCount(id,date);
        pageCount = Math.ceil(pageCount / pageSize);
        List<Leaves> leavesList = leavesDao.leavesList(id,pageIndex, pageSize,date);
        Map<String, Object> map = new HashMap<>();
        map.put("pageCount", pageCount);
        map.put("leavesList", leavesList);
        return R.ok(map);
    }

    @Override
    public R addLeaves(Leaves leaves) {
        return R.ok(leavesDao.addLeaves(leaves));
    }



    //查询待审核
    @Override
    public R viewLeaves(Integer pageIndex, Integer pageSize) {
        pageIndex = (pageIndex - 1) * pageSize;
        double pageCountleaves = leavesDao.PageCountLeaves();
        pageCountleaves = Math.ceil(pageCountleaves / pageSize);
        List<Leaves> leavesList = leavesDao.getLeaves(pageIndex,pageSize);
        Map<String, Object> map = new HashMap<>();
        map.put("pageCountleaves", pageCountleaves);
        map.put("leavesList", leavesList);
        return R.ok(map);
    }
    //    操作审核请假
    @Override
    public void reviewLeave( Map<String, Object> params) {
        leavesDao.updateLeaveStatus(params);
    }
}
